package com.iknow.activity;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask.Status;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.iknow.IKnow;
import com.iknow.IKnowApiV4;
import com.iknow.User;
import com.iknow.app.IKnowSystemConfig;
import com.iknow.db.IKnowDataBase;
import com.iknow.task.GenericTask;
import com.iknow.task.TaskAdapter;
import com.iknow.task.TaskListener;
import com.iknow.task.TaskParams;
import com.iknow.task.TaskResult;
import com.iknow.util.Regex;
import com.iknow.util.StringUtil;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FeedbackActivity extends Activity
{
  private ProgressDialog dialog;
  private View.OnClickListener feedbackClickListener;
  private Button mBackButton;
  private Context mContext;
  private EditText mDataEdit;
  private EditText mEmailEdit;
  private FeedbackTask mFeedbackTask;
  private Button mFeekbackBtn = null;
  private TaskListener mTaskListener;

  public FeedbackActivity()
  {
    this.mDataEdit = null;
    this.mEmailEdit = null;
    this.mFeedbackTask = null;
    this.feedbackClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        String str1 = FeedbackActivity.access$0(this.this$0).getText().toString();
        if (StringUtil.isEmpty(str1))
          Toast.makeText(FeedbackActivity.access$1(this.this$0), "请先填写反馈内容", 0).show();
        while (true)
        {
          String str2;
          do
            while (true)
            {
              return;
              str2 = FeedbackActivity.access$2(this.this$0).getText().toString();
              if (str2 != null)
                str2 = str2.trim();
              Matcher localMatcher = Regex.EMAIL_ADDRESS_PATTERN.matcher(str2);
              if ((StringUtil.isEmpty(str2)) || (localMatcher.matches()))
                break;
              Toast.makeText(FeedbackActivity.access$1(this.this$0), "请先填写邮箱地址", 0).show();
            }
          while ((FeedbackActivity.access$3(this.this$0) != null) && (FeedbackActivity.access$3(this.this$0).getStatus() == AsyncTask.Status.RUNNING));
          FeedbackActivity.access$4(this.this$0, new FeedbackActivity.FeedbackTask(this.this$0, null));
          FeedbackActivity.access$3(this.this$0).setListener(FeedbackActivity.access$5(this.this$0));
          TaskParams localTaskParams = new TaskParams();
          localTaskParams.put("des", str1);
          localTaskParams.put("email", str2);
          FeedbackActivity.FeedbackTask localFeedbackTask = FeedbackActivity.access$3(this.this$0);
          TaskParams[] arrayOfTaskParams = new TaskParams[1];
          arrayOfTaskParams[0] = localTaskParams;
          localFeedbackTask.execute(arrayOfTaskParams);
        }
      }
    };
    this.mTaskListener = new TaskAdapter(this)
    {
      public String getName()
      {
        return "Feedback";
      }

      public void onCancelled()
      {
      }

      public void onPostExecute(, TaskResult paramTaskResult)
      {
        if (paramTaskResult == TaskResult.OK)
          FeedbackActivity.access$7(this.this$0);
        while (true)
        {
          return;
          FeedbackActivity.access$8(this.this$0, ((FeedbackActivity.FeedbackTask)paramGenericTask).getMsg());
        }
      }

      public void onPreExecute()
      {
        FeedbackActivity.access$6(this.this$0);
      }

      public void onProgressUpdate(, Object paramObject)
      {
      }
    };
  }

  private void initView()
  {
    String str;
    this.mFeekbackBtn = ((Button)findViewById(2131296319));
    this.mFeekbackBtn.setOnClickListener(this.feedbackClickListener);
    this.mDataEdit = ((EditText)findViewById(2131296317));
    this.mEmailEdit = ((EditText)findViewById(2131296318));
    User localUser = IKnow.mIKnowDataBase.getUser();
    if ((localUser != null) && (!(StringUtil.isEmpty(localUser.getEmail()))))
      str = localUser.getEmail();
    while (true)
    {
      this.mEmailEdit.setText(str);
      findViewById(2131296344).setVisibility(8);
      this.mBackButton = ((Button)findViewById(2131296342));
      this.mBackButton.setOnClickListener(new View.OnClickListener(this)
      {
        public void onClick()
        {
          this.this$0.finish();
        }
      });
      return;
      str = IKnow.mSystemConfig.getString("email");
    }
  }

  private void onFeedbackBegin()
  {
    this.dialog = ProgressDialog.show(this, "", getString(2131361872), true);
    this.dialog.setCancelable(true);
  }

  private void onFeedbackFailure(String paramString)
  {
    Toast.makeText(this, paramString, 0).show();
    if (this.dialog != null)
      this.dialog.dismiss();
  }

  private void onFeedbackSuccess()
  {
    if (this.dialog != null)
      this.dialog.dismiss();
    Toast.makeText(this, "感谢您提供反馈", 0).show();
    finish();
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    requestWindowFeature(1);
    setContentView(2130903055);
    this.mContext = this;
    initView();
  }

  private class FeedbackTask extends GenericTask
  {
    private String msg = null;

    protected TaskResult _doInBackground()
    {
      TaskResult localTaskResult;
      TaskParams localTaskParams = paramArrayOfTaskParams[0];
      Object[] arrayOfObject = new Object[1];
      arrayOfObject[0] = Integer.valueOf(2131361872);
      publishProgress(arrayOfObject);
      try
      {
        String str1 = localTaskParams.getString("email");
        String str2 = localTaskParams.getString("des");
        IKnow.mApi.feedback(str1, str2);
        localTaskResult = TaskResult.OK;
        return localTaskResult;
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
        this.msg = "网络超时，稍候再试";
        localTaskResult = TaskResult.FAILED;
      }
    }

    public String getMsg()
    {
      return this.msg;
    }
  }
}